// pages/orderDetail/applyRefund.js
const app = getApp()
var wh = require("../../utils/wh.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    num: '',
    remark: '',
    detail:'',
    order_id:''
  },

  bindRemark: function(e) {
    this.setData({
      remark: e.detail.value
    })
  },
  // 订单详情
  item_detail(order_id) {
    let that = this;
    wh.Post('/api/mall.order/item_detail', {
      order_id: order_id
    }, function(res) {
      console.log(res)
        that.setData({
          detail: res
        })
    })
  },
  // 发送申请
  send(){
    let that = this;
    wh.Post('/api/mall.order/refund', {
      order_id: that.data.order_id,
      refund_info: that.data.remark
    },function(res){
      wx.showToast({
        title: '申请成功',
        icon: 'none',
        duration: 2000,
        complete: function () {
          setTimeout(function () {
            wx.navigateTo({
              url: '../order/order?c=-1'
            })
          }, 2000);
        }
      });
    })
  },
  // 跳转至商品详情
  toGoods(e) {
    let that = this,
      id = e.currentTarget.dataset.id,
      act_type = e.currentTarget.dataset.act_type;
    if (act_type == 1) {
      wx.navigateTo({
        url: '../details/details?goods_id=' + id,
      })
    } else if (act_type == 2) {
      wx.navigateTo({
        url: '../cutDetails/cutDetails?bargainId=' + id,
      })
    } else if (act_type == 3) {
      wx.navigateTo({
        url: '../killDetails/killDetails?seckill_id=' + id,
      })
    } else if (act_type == 4) {
      wx.navigateTo({
        url: '../groupDetails/groupDetails?group_id=' + id,
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options.order_id)
    this.item_detail(options.order_id)
    this.setData({
      order_id: options.order_id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})